<template>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column label="评论书籍" width="180">
      <template slot-scope="scope">
        <span style="margin-left: 10px">{{ scope.row.name }}</span>
      </template>
    </el-table-column>
    <el-table-column label="评论内容" width="180">
      <template slot-scope="scope">
        <span style="margin-left: 10px">{{ scope.row.name }}</span>
      </template>
    </el-table-column>
    <el-table-column label="创建时间" width="180">
      <template slot-scope="scope">
        <div slot="reference" class="name-wrapper">
          <el-tag size="medium">{{ scope.row.date }}</el-tag>
        </div>
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)"
          >删除</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  data() {
    return {
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄"
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄"
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄"
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄"
        }
      ]
    };
  },
  mounted: function() {
    this.$axios({
      method: "get",
      url: "http://127.0.0.1:8000/comment",
      data: {
        //这里是发送给后台的数据
        token: localStorage.getItem("localStorage")
      }
    })
      .then(response => {
        var data = response.data;
        //   this.tableData = data;
      })
      .catch(error => {
        this.msg = msg;
        //如果token过期则重新获取token
      });
  },
  methods: {
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      this.$axios({
        method: "delete",
        url: "http://127.0.0.1:8000/comment/",
        data: {
          //这里是发送给后台的数据
          token:localStorage.getItem("localStorage"),
          cid: bid
        }
      })
        .then(response => {
          var data = response.data;
          //重新加载页面即可
        })
        .catch(error => {
          this.msg = msg;
          //如果token过期则重新获取token
        });
    }
  }
};
</script>

<style></style>
